package com.njg.juc.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @auther zzyybs@126.com
 * @Date 2025-04-24 8:28
 * @Description: TODO
 */
public class CasHello
{
    public static void main(String[] args)
    {
       AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.get());

        System.out.println(atomicInteger.compareAndSet(5, 2025)+"-->" +atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 2022)+"-->" +atomicInteger.get());

        System.out.println("atomicInteger.getAndIncrement() = " + atomicInteger.getAndIncrement());//i++
        System.out.println("atomicInteger.get() = " + atomicInteger.get());

        System.out.println("atomicInteger.incrementAndGet() = " + atomicInteger.incrementAndGet());//++i

        System.out.println("atomicInteger.addAndGet(3) = " + atomicInteger.addAndGet(3));

        System.out.println("atomicInteger.getAndDecrement() = " + atomicInteger.getAndDecrement());//i--
        System.out.println("atomicInteger.get() = " + atomicInteger.get());

        System.out.println("atomicInteger.decrementAndGet() = " + atomicInteger.decrementAndGet());//--i

        System.out.println("atomicInteger.addAndGet(-3) = " + atomicInteger.addAndGet(-3));

    }
}
